package com.web.base.core.util;

import com.blue.jdbc.Page;
import com.web.base.core.message.BankRequest;
import com.web.base.core.message.BankResponse;
import com.web.base.core.model.Bank;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 银行转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2018年06月19日
 */
public class BankConvertor
{
	private BankConvertor()
	{
	}
	
	public static Bank toBank(BankRequest request)
	{
		if (request == null)
			return null;
		
		Bank bank = new Bank();
		bank.setId(request.getId());
		bank.setCode(request.getCode());
		bank.setName(request.getName());
		bank.setShortName(request.getShortName());
		bank.setSort(request.getSort());
		bank.setState(request.getState());
		return bank;
	}
	
	public static List<Bank> toBank(List<BankRequest> requestList)
	{
		List<Bank> list = new ArrayList<>();
		if (requestList == null || requestList.isEmpty())
			return list;
		
		for (BankRequest request : requestList)
		{
			list.add(toBank(request));
		}
		return list;
	}
	
	public static BankResponse toResponse(Bank bank)
	{
		if (bank == null)
			return null;
		
		BankResponse response = new BankResponse();
		response.setId(bank.getId());
		response.setCode(bank.getCode());
		response.setName(bank.getName());
		response.setShortName(bank.getShortName());
		response.setSort(bank.getSort());
		response.setState(bank.getState());
		return response;
	}
	
	public static List<BankResponse> toResponse(List<Bank> list)
	{
		List<BankResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (Bank bank : list)
		{
			responseList.add(toResponse(bank));
		}
		return responseList;
	}
	
	public static Map<Integer, BankResponse> toResponse(Map<Integer, Bank> map)
	{
		Map<Integer, BankResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, Bank> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<BankResponse> toResponse(Page<Bank> page)
	{
		if (page == null)
			return null;
		
		Page<BankResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
